package com.cn.kehong.controller;


import com.cn.kehong.api.IProductDianciFenjiRecordService;
import com.cn.kehong.domain.ProductDianciFenjiRecord;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dianfenji")
public class ProductDianciFenjiRecordController {

    @Autowired
    private IProductDianciFenjiRecordService productDianciFenjiRecordService;

    @RequestMapping("/getProductDianciFenjiRecordList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductDianciFenjiRecord>> getProductDianciFenjiRecordList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductDianciFenjiRecord> > response = new JsonResponse<List<ProductDianciFenjiRecord> >();
        List<ProductDianciFenjiRecord> lists = productDianciFenjiRecordService.getProductDianciFenjiRecordList(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/updateProductDianciFenjiRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateProductDianciFenjiRecord(ProductDianciFenjiRecord productDianciFenjiRecord, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciFenjiRecordService.updateProductDianciFenjiRecord(productDianciFenjiRecord);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/addProductDianciFenjiRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addProductDianciFenjiRecord(ProductDianciFenjiRecord productDianciFenjiRecord, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciFenjiRecordService.addProductDianciFenjiRecord(productDianciFenjiRecord);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteProductDianciFenjiRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteProductDianciFenjiRecord(String id, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciFenjiRecordService.deleteProductDianciFenjiRecord(id);
        return CommonUtil.getResponseData(response,result);
    }
}
